/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufc.quixada.adrs.service;

import br.ufc.quixada.adrs.dao.DescarteDAO;
import br.ufc.quixada.adrs.model.Descarte;
import br.ufc.quixada.adrs.util.Msg;
import java.sql.SQLException;
import java.util.List;
import org.slf4j.LoggerFactory;

/**
 *
 * @author Caio
 */
public class DescarteService {

    private final DescarteDAO dao = new DescarteDAO();

    public boolean insertDescarte(Descarte descarte) {
        try {
            dao.insert(descarte);
            return true;
        } catch (SQLException ex) {
            LoggerFactory.getLogger(this.getClass()).error(Msg.EXCEPTION_MESSAGE, this.getClass().getSimpleName(), ex);
            return false;
        }
    }

    public boolean updateDescarte(Descarte descarte) {
        try {
            dao.update(descarte);
            return true;
        } catch (SQLException ex) {
            LoggerFactory.getLogger(this.getClass()).error(Msg.EXCEPTION_MESSAGE, this.getClass().getSimpleName(), ex);
            return false;
        }
    }

    public boolean deleteDescarte(Long id) {
        try {
            dao.delete(id);
            return true;
        } catch (SQLException ex) {
            LoggerFactory.getLogger(this.getClass()).error(Msg.EXCEPTION_MESSAGE, this.getClass().getSimpleName(), ex);
            return false;
        }
    }

    public Descarte getDescarteById(Long id) {
        try {
            Descarte descarte = dao.getById(id);
            return descarte;
        } catch (SQLException ex) {
            LoggerFactory.getLogger(this.getClass()).error(Msg.EXCEPTION_MESSAGE, this.getClass().getSimpleName(), ex);
            return null;
        }
    }

    public List<Descarte> getDescartesByQuestionarioQuantitativoId(Long id) {
        try {
            List<Descarte> descartes = dao.getByQuestionarioQuantitativoId(id);
            return descartes;
        } catch (SQLException ex) {
            LoggerFactory.getLogger(this.getClass()).error(Msg.EXCEPTION_MESSAGE, this.getClass().getSimpleName(), ex);
            return null;
        }
    }

    public List<Descarte> getDescartesByTipoAnimalId(Long id) {
        try {
            List<Descarte> descartes = dao.getByTipoAnimalId(id);
            return descartes;
        } catch (SQLException ex) {
            LoggerFactory.getLogger(this.getClass()).error(Msg.EXCEPTION_MESSAGE, this.getClass().getSimpleName(), ex);
            return null;
        }
    }
}
